﻿using UnityEngine;
using TinyToolKit.FSM;

namespace TinyToolKit.Demo 
{
    public class Enemy : MonoBehaviour
    {
        public string fsmName = "Enemy";
        public float detectRadius = 3;
        public float moveSpeed = 3;
        private TFsmManager _fsmManager;
        private IFsmSystem<Enemy> _Fsm;
        private Transform range;

        public void Start()
        {
            _fsmManager = TinyTool.Instance.GetManager<TFsmManager>();
            
            // 参数传入有限状态机名称、拥有者和所有需要的状态
            _Fsm = _fsmManager.CreateFsm(fsmName, this, new ChaseState(),new PatrolState());
            _Fsm.SetData(TinyDefine_Demo.FSM_EnemyTF, transform);
            _Fsm.SetData(TinyDefine_Demo.FSM_DetectedRadius, detectRadius);
            _Fsm.SetData(TinyDefine_Demo.FSM_EnemySpeed, moveSpeed);
            _Fsm.Start(typeof(ChaseState));

            range = transform.Find("DetectedRange");
            range.localScale = detectRadius * 2 * Vector3.one;
        }

        private void OnDisable()
        {
            //销毁
            _fsmManager.DestroyFsm(_Fsm);
        }
    }
}

